package com.soho.cron;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

import com.soho.helper.PrintHelper;

public class CronMain {

	public static void run(){
		try {
		 SchedulerFactory schedulerFactory = new StdSchedulerFactory();
	        Scheduler scheduler = schedulerFactory.getScheduler();
	 
	        // define the job and tie it to the SimpleJob class
	        JobDetail job = JobBuilder.newJob(TaskJob.class)
	                .withIdentity("myJob", "myGroup")
	                .build();
	 
	        // create the trigger and define its schedule to run every 1 seconds
	        Trigger trigger = TriggerBuilder.newTrigger()
	                .withIdentity("myTrigger", "myGroup")
	                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
	                        .withIntervalInSeconds(1)
	                        .repeatForever())
	                .build();
	 
	        // add the job details to the scheduler and associate it with the trigger
	        scheduler.scheduleJob(job, trigger);
	 
	        // start the scheduler
	        scheduler.start();
	        PrintHelper.print("Start Cron RUN");
		}catch(Exception e) {
			PrintHelper.print(e);
		}
	}
	public static void main(String[] args) {
		try {
			run();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
